/**
 * 判断对象中是否存在某个key
 * @param obj
 * @param key
 */
export function hasKey<T>(obj: T, key: string): obj is T {
    return key in obj;
}

/**
 * 根据key获取对象对应值
 * @param obj
 * @param key
 */
export function getValue<T, K extends keyof T>(obj: T, key: K): T[K]{
    return obj[key]
}

/**
 * 合并对象，以第一个参数为模板
 * @param model
 * @param data
 */
export function mergeObjects(model:{[key: string]: any}, data:{[key: string]: any}){
    for (let objKey in model) {
        model[objKey] = data[objKey]
    }
}

export function randomStr() {
    let str = '';
    let chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    for (let i = 0; i < 7; i++) {
        str += chars.charAt(Math.floor(Math.random() * chars.length));
    }
    return str;
}
